import modelExtend from 'dva-model-extend';

export const model = {
  reducers: {
    updateState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};

export const pageModel = modelExtend(model, {

  state: {
    list: [],
    pagination: {
      showSizeChanger: true,
      showQuickJumper: true,
      showTotal: total => `总共 ${total} 项`,
    },
  },

  reducers: {
    querySuccess(state, { payload }) {
      const { list, pagination, tableDisplay } = payload;

      return {
        ...state,
        list,
        tableDisplay,
        pagination: {
          ...state.pagination,
          ...pagination,
        },
      };
    },
  },

});

export default {
  pageModel,
  model
};
